﻿using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEditor;
using UnityEngine;

public class BattleSceneAStarRegion : MonoBehaviour
{
    public float left;
    public float right;
    public float top;
    public float bottom;

    public float propWidth;
    public float propHeight;
    public float propCellSize;
    
    public float cellSize = 1;
    private void OnDrawGizmos()
    {
        var center = /*new Vector3((left + right) / 2, 0, (top + bottom) / 2) + */transform.position;
        var q = Quaternion.FromToRotation(Vector3.forward,transform.forward);
        Gizmos.color = Color.white;
        Gizmos.DrawLine(q * new Vector3(left,1,top) + center,q * new Vector3(left,1,bottom) + center);
        Gizmos.DrawLine(q * new Vector3(left,1,bottom) + center, q * new Vector3(right,1,bottom) + center);
        Gizmos.DrawLine(q * new Vector3(right,1,bottom) + center, q * new Vector3(right,1,top) + center);
        Gizmos.DrawLine(q * new Vector3(right,1,top) + center, q * new Vector3(left,1,top) + center);

        var width = right - left;
        var height = top - bottom;
        var halfW = Mathf.FloorToInt(propWidth / propCellSize / 2f - 0.5f) + propCellSize / 2;
        var halfH = Mathf.FloorToInt(propHeight / propCellSize / 2f - 0.5f) + propCellSize / 2;
        Gizmos.color = Color.green;
        for (float i = -halfW; i <= halfW; i += propCellSize)
        {
            Gizmos.DrawLine(q * new Vector3(i,1,-halfH) + center,q * new Vector3(i,1,halfH) + center);
        }
        for (float i = -halfH; i <= halfH; i += propCellSize)
        {
            Gizmos.DrawLine(q * new Vector3(-halfW,1,i) + center,q * new Vector3(halfW,1,i) + center);
        }
    }
}
